#include "ControllerZone.h"
#include "UGUI/ugui.h"

static UG_GUI gui;
static uint32_t RGBMap[1024*1024];  // 4M
static void ugui_pset(UG_S16 x, UG_S16 y, UG_COLOR t)
{
    //OLED_DrawPoint(x, y, t);
    //RGBMap[x*1024+y] = t;
    RGBMap[(x<<10)+y] = t;
}

ControllerZone::ControllerZone(unsigned int zone_idx, bool reverse, uint16_t rgbw, uint16_t rgbh):
    zone_idx(zone_idx),
    reverse(reverse),
    RGBW(rgbw),
    RGBH(rgbh)
{
    /* Init ?UI */
    UG_Init(&gui,(void(*)(UG_S16,UG_S16,UG_COLOR))ugui_pset,RGBW, RGBH);
    //UG_FontSelect(&FONT_8X12);
    //UG_FontSelect(&FONT_32X53);
    UG_FontSelect(&FONT_4X6);
    UG_FillScreen( C_BLACK );
};

ControllerZone::~ControllerZone()
{
    ;
}

unsigned int* ControllerZone::map()
{
    return RGBMap;
}
void ControllerZone::SetAllZoneLEDs(RGBColor color, int brightness)
{
    //controller->SetAllZoneLEDs(zone_idx, ColorUtils::apply_brightness(color, brightness / 100.f));
    for(uint32_t idx=0; idx<(sizeof(RGBMap)/sizeof(RGBMap[0])); idx++) RGBMap[idx] = color;
}

void ControllerZone::SetLED(int idx, RGBColor color, int brightness)
{
     //controller->SetLED(idx, ColorUtils::apply_brightness(color, brightness / 100.f));
    RGBMap[idx] = color;
}

void ControllerZone::SetLED(int x, int y, RGBColor color, int brightness)
{
    RGBMap[x*RGBW+y] = color;
}

uint32_t ControllerZone::GetLED(int x, int y)
{
    return RGBMap[x*RGBW+y];
}
